package com.zmn.oms.services.impl.work;

import com.vdurmont.emoji.EmojiParser;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.model.entity.work.OrderWorkPosition;
import com.zmn.oms.persistence.interfaces.work.OrderWorkPositionDao;
import com.zmn.oms.services.interfaces.work.OrderWorkPositionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author sunlife
 * @date:2020/8/17 4:59 下午
 * description:
 */
@Service
public class OrderWorkPositionServiceImpl implements OrderWorkPositionService {
    @Resource
    OrderWorkPositionDao orderWorkPositionDao;

    @Override
    public OrderWorkPosition findById(Long positionId) {
        OrderWorkPosition orderWorkPosition = orderWorkPositionDao.selectByPrimaryKey(positionId);
        if (orderWorkPosition != null && StringUtil.isNotBlank(orderWorkPosition.getCreater())) {// 表情符号转换为字符
            orderWorkPosition.setCreater(EmojiParser.parseToUnicode(orderWorkPosition.getCreater()));
        }
        if (orderWorkPosition != null && StringUtil.isNotBlank(orderWorkPosition.getUpdater())) {// 表情符号转换为字符
            orderWorkPosition.setUpdater(EmojiParser.parseToUnicode(orderWorkPosition.getUpdater()));
        }
        return orderWorkPosition;
    }

    @Override
    public int insert(OrderWorkPosition record) {

        // region 表情符号转换为字符
        if (StringUtil.isNotBlank(record.getCreater())) {
            record.setCreater(EmojiParser.parseToAliases(record.getCreater()));
        }
        if (StringUtil.isNotBlank(record.getUpdater())) {
            record.setUpdater(EmojiParser.parseToAliases(record.getUpdater()));
        }
        // endRegion
        return orderWorkPositionDao.insertSelective(record);
    }

    @Override
    public int updateById(OrderWorkPosition record) {
        if (StringUtil.isNotBlank(record.getUpdater())) {
            record.setUpdater(EmojiParser.parseToAliases(record.getUpdater()));
        }
        return orderWorkPositionDao.updateByPrimaryKeySelective(record);
    }
}
